﻿using System;
using Transformable_Engine_v2.Engine.Transformable_Math.Geometry;

namespace Transformable_Engine_v2.Engine.Animation.PositionAnimation
{
    public class PositionUniformLinearAnimation : BaseAnimation
    {
        public PositionUniformLinearAnimation(double delay, TE_Vector2 speed, bool autoStart = true)
            : this(delay, speed, TE_Vector2.Zero, autoStart)
        {
        }

        public PositionUniformLinearAnimation(double delay, TE_Vector2 speed, TE_Vector2 acceleration, bool autoStart = true)
            : base(0, false, delay, autoStart)
        {
            Speed = speed.ToGridbound();
            Acceleration = acceleration.ToGridbound();
        }

        public TE_Vector2 Speed { get; private set; }
        public TE_Vector2 Acceleration { get; private set; }
        public IPositionAnimatable AffectedObject { private get; set; }

        public override void Update(TimeSpan gameTime)
        {
            
        }

        public override void FixedStepUpdate(TimeSpan gameTime)
        {
            if(AffectedObject != null)
                AffectedObject.AddToPosition(Speed * gameTime.TotalSeconds);

            Speed += Acceleration*gameTime.TotalSeconds;

            base.FixedStepUpdate(gameTime);
        }

        public override void Die()
        {
            AffectedObject = null;
            base.Die();
        }

        public void FlipHorizontal()
        {
            Speed.X = -Speed.X;
            Acceleration.X = -Acceleration.X;
        }

        public void FlipVertical()
        {
            Speed.Y = -Speed.Y;
            Acceleration.Y = -Acceleration.Y;
        }
    }
}